package com.ufaud.ais.sys.entity;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;
import javax.persistence.Transient;

import com.ufaud.ais.pub.entity.BaseEntity;

@Entity
@Table(name = "role")
public class Role extends BaseEntity<Long> {

	@Id
	@GeneratedValue
	@Column(name = "role_id")
	private Long roleId;

	@Column(name = "role_name")
	private String roleName;

	@Column(name = "role_code", nullable = true, unique = true)
	private String roleCode;

	@ManyToMany(fetch = FetchType.LAZY)
	@JoinTable(name = "role_menu_item_relation", joinColumns = @JoinColumn(name = "role_id"), inverseJoinColumns = @JoinColumn(name = "menu_item_id"))
	private Set<MenuItem> menuItemSet = new HashSet<MenuItem>();

	public Long getRoleId() {
		return roleId;
	}

	public void setRoleId(Long roleId) {
		this.roleId = roleId;
	}

	public String getRoleName() {
		return roleName;
	}

	public void setRoleName(String roleName) {
		this.roleName = roleName;
	}

	public String getRoleCode() {
		return roleCode;
	}

	public void setRoleCode(String roleCode) {
		this.roleCode = roleCode;
	}

	public void setMenuItemSet(Set<MenuItem> menuItemSet) {
		this.menuItemSet = menuItemSet;
	}

	public Set<MenuItem> getMenuItemSet() {
		return menuItemSet;
	}

	public boolean addMenuItem(MenuItem menuItem) {
		return menuItemSet.add(menuItem);
	}

	public boolean removeMenuItem(MenuItem menuItem) {
		return menuItemSet.remove(menuItem);
	}

	@Override
	@Transient
	public String getPropertyNameOfId() {
		return "roleId";
	}

}
